// import request from 'superagent';
// import jsonp from 'superagent-jsonp';
import axios from 'axios'

const state = {
    events: [],
    temp: [],
    skip: 0,
    eventItem: {}
}

const mutations= {
    loadMore (state, payload) {
        state.skip += 3;
        state.events  = state.events.concat(payload.result);
    },
    getSingleEvent (state, payload) {
        state.eventItem = payload.result;
    }
}

const actions = {
    loadMore ({commit, state}) {
        axios.get('/v2/event/list?loc=108288&start=' +
            state.skip + '&count=3')
            .then(function(result){
                commit({
                    type: 'loadMore',
                    result: result.data.events
                })
            })
            .catch(function(error){
                console.log(error);
            })
    },

    getSingleEvent ({commit, state}, payload){
        axios.get('/v2/event/' + payload.id)
        .then(function(result) {
            commit({
                type: 'getSingleEvent',
                result: result.data
            })
            console.log('activities',result.data)
        })
        .catch(function(error) {
            console.log(error);
        })
    }
}


export default {
    state,
    mutations,
    actions
}